package com.example.foodapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.foodapp.R;
import com.example.foodapp.bean.Food;

import java.util.ArrayList;
import java.util.List;

public class MyAdapter extends BaseAdapter {

    List<Food.ListDTO> list=new ArrayList<>();
    Context context;

    public MyAdapter(List<Food.ListDTO> list,Context context){
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = View.inflate(context, R.layout.dishes,null);

        ImageView iv = view.findViewById(R.id.iv_images);
        TextView tv = view.findViewById(R.id.tv_title);
        TextView tvIntro = view.findViewById(R.id.tv_dishesDescription);
        TextView tvPrice = view.findViewById(R.id.tv_dishesPrice);

        Food.ListDTO data =  list.get(position);

        iv.setImageResource(R.drawable.abc_vector_test);//图标
        tv.setText(data.getName());//名
        tvIntro.setText(data.getDescription());//简介
        tvPrice.setText(String.valueOf("价格："+data.getPrice()));//价格
        return view;
    }
}
